package com.linwancun.lwcyback.service;

import com.linwancun.lwcyback.mapper.ChatrecordMapper;
import com.linwancun.lwcyback.model.Chatrecord;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;

@Service
public class ChatRecordServiceImpl implements ChatRecordService {
    @Resource
    private ChatrecordMapper chatrecordMapper;

    @Override
    public void insert(Chatrecord object) {
        chatrecordMapper.insert(object);
    }

    @Override
    public void save(Chatrecord object) {
        chatrecordMapper.updateByPrimaryKey(object);
    }

    @Override
    public List<Chatrecord> getAll() {
        return chatrecordMapper.list(new Chatrecord());
    }

    @Override
    public Chatrecord find(Chatrecord object) {
        return chatrecordMapper.find(object);
    }

    @Override
    public void delete(Chatrecord object) {
        chatrecordMapper.deleteByPrimaryKey(object.getChatid());
    }

    @Override
    public List<Chatrecord> getList(Chatrecord object) {
        return chatrecordMapper.list(object);
    }

    @Override
    public List<Chatrecord> getNewRecord(Chatrecord object) {
        List<Chatrecord> list = getList(object);
        Iterator<Chatrecord> iterator = list.iterator();
        while (iterator.hasNext()) {
            Chatrecord chatrecord = iterator.next();
            chatrecord.setIsread(1);
            save(chatrecord);
        }
        return list;
    }
}
